package com.iwhalecloud.bss.kite.cucc.service.pos.handler;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;

import com.github.pagehelper.PageInfo;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteDateUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.reception.ICustReceptionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.KiteCustomerInfoReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosGoodsDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosGoodsFeeDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosProductDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosUserDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.scene.CuccCustInfoDTO;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.ExtOrderInfoCache;
import com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.BcmcPosContext;
import com.iwhalecloud.bss.kite.cucc.service.util.ChangeTypeUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.KiteDcPublicUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.cache.DcSystemParamCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProdFeeCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProductCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Product;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.enums.ActionType;
import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.ord.pos.vo.KitePosInstVO;
import com.iwhalecloud.bss.kite.service.ord.pos.vo.KitePosProdInstVO;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.bss.provinces.chongqing.utils.StrTools;

/**
 * <Description> <br>
 * 下单服务辅助工具类
 *
 * @author XXZ<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2020年12月7日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.pos.handler <br>
 */
public abstract class CuccPosServiceUtils {
    // 下单BCMC流程商品分类配置
    private static final String BCMC_GOODS_CONGIF = "BCMC_GOODS_CONGIF";

    /**
     * Description: <br>
     * 获取场景实例根商品实例
     *
     * @param sceneInstId
     * @param custId
     * @return <br>
     */
    public static KiteOfferInst getRootOfferInst(String sceneInstId, String custId) {
        KiteOfferInst offerInst = null;
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        // 获取场景中受理商品实例
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId, custId);
        if (Objects.nonNull(sceneInst)) {
            // 获取跟商品实例
            offerInst = querySceneInstService.getOfferInst(sceneInst.getCustId(), sceneInst.getRootInstId());
        }
        return offerInst;
    }

    /**
     * Description: <br>
     * 获取场景实例根商品实例
     *
     * @param sceneInstId
     * @return <br>
     */
    public static KiteOfferInst getRootOfferInstBySceneInstId(String sceneInstId) {
        KiteOfferInst offerInst = null;
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        // 获取场景中受理商品实例
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        if (Objects.nonNull(sceneInst)) {
            // 获取跟商品实例
            offerInst = querySceneInstService.getOfferInst(sceneInst.getCustId(), sceneInst.getRootInstId());
        }
        return offerInst;
    }

    /**
     * Description: <br>
     * 获取上下文用户实例ID
     */
    public static String getUserInstId(BcmcPosContext context) {
        List<KitePosUserDTO> users = context.getPosDto().getUsers();
        if (!KiteListUtils.isEmpty(users)) {
            return Optional.ofNullable(users.get(0)).map((user) -> user.getInstanceId()).orElse("");
        }
        return "";
    }

    /**
     * Description: <br>
     * 获取场景实例
     *
     * @author XXX<br>
     * @taskId <br>
     * @param context
     * @return <br>
     */
    public static KiteSceneInst getSceneInst(BcmcPosContext context) {
        KiteSceneInst sceneInst = context.getPosSceneBO().getSceneInst();
        if (Objects.isNull(sceneInst)) {
            sceneInst = SpringUtil.getBean(IQuerySceneInstService.class).getSceneInst(context.getSceneInstId());
            context.getPosSceneBO().setSceneInst(sceneInst);
        }
        return sceneInst;
    }

    /**
     * Description: <br>
     * 获取场景创建时间
     *
     * @author XXZ<br>
     * @taskId <br>
     * @param sceneInstId
     * @return <br>
     */
    public static String getSceneCreateDate(BcmcPosContext context) {
        KiteSceneInst sceneInst = getSceneInst(context);
        // 获取场景创建时间
        Date createDate = sceneInst.getCreateDate();
        return KiteDateUtils.formatDate(createDate, KiteDateUtils.DATE_TIME_FORMAT_14);
    }

    /**
     * Description: <br>
     * 根据产品实例ID获取产品实例对象
     *
     * @author XXZ<br>
     * @taskId <br>
     * @param context
     * @param prodInstId <br>
     */
    public static KitePosProdInstVO getProdInstVOByInstId(BcmcPosContext context, String prodInstId) {
        KitePosProdInstVO prodInstVO = null;
        Map<String, KitePosProdInstVO> prodInstMap = context.getPosSceneBO().getProdInstMap();
        prodInstVO = prodInstMap.get(prodInstId);
        return prodInstVO;
    }

    /**
     * Description: <br>
     * 获取实例属性变更操作类型
     */
    public static String getAttrChangeType(KitePosInstVO instVO, KiteAttr attr) {
        // 默认属性新增操作
        String changeType = ChangeTypeUtils.getChangeType(ActionType.A.name());
        if (StringUtils.equals(instVO.getActionType(), ActionType.A.name())) {
            return changeType;
        }
        else if (StringUtils.equals(instVO.getActionType(), ActionType.M.name())) {
            // 实例变更，则需要判断属性变更集合
            Map<String, Object> oldAttrMap = instVO.getInstOldAttrs();
            if (MapUtils.isEmpty(oldAttrMap)) {
                // 属性没有变动，默认都是K
                changeType = ChangeTypeUtils.getChangeType(ActionType.K.name());
            }
            else {
                if (Objects.nonNull(oldAttrMap.get(attr.getFieldName()))) {
                    // 存在变更值
                    changeType = ChangeTypeUtils.getChangeType(ActionType.M.name());
                }
                else {
                    changeType = ChangeTypeUtils.getChangeType(ActionType.K.name());
                }
            }
        }

        return changeType;
    }

    /**
     * Description: <br>
     * 判断是否属于BCMC流程的商品分类
     *
     * @author XXZ<br>
     * @taskId <br>
     * @param offerId
     * @return <br>
     */
    public static boolean checkBcmcGoodsCategroy(String offerId) {
        Offer offer = OfferCache.get(offerId);
        if (Objects.nonNull(offer)) {
            // 判断商品分类是否属于配置中
            String categroyIds = DcSystemParamCache.getDcParamVal(BCMC_GOODS_CONGIF);
            if (StrTools.isIndexOf(categroyIds, offer.getCateId(), ",")) {
                return Boolean.TRUE;
            }
        }

        return Boolean.FALSE;
    }

    /**
     * Description: <br>
     * 判断是否是资费产品
     *
     * @author XXZ<br>
     * @taskId <br>
     * @param prodId
     * @return <br>
     */
    public static boolean checkBillProdType(String prodId) {
        Product prodSpec = ProductCache.get(prodId);
        String prodUseType = prodSpec.getProdUseType();
        if (KiteStringUtils.equals(prodUseType, LocalKeyConsts.PROD_USE_TYPE_2000)) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    public static String getCateId(String sceneInstId,String cust_id) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        String rootInstId = querySceneInstService.getSceneInst(sceneInstId).getRootInstId();
        InstType instType = querySceneInstService.getSceneInst(sceneInstId).getRootInstType();
        KiteInst kiteInst = querySceneInstService.getKiteInst(cust_id, instType, rootInstId);
        String cateId = OfferCache.get(kiteInst.getSpecId()).getCateId();
        return cateId;
    }

    public static List<String> listCateIds(String sceneInstId,String custId) {
        List<String> cateIds = new ArrayList<>();
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        String rootInstId = querySceneInstService.getSceneInst(sceneInstId).getRootInstId();
        InstType instType = querySceneInstService.getSceneInst(sceneInstId).getRootInstType();
        KiteInst kiteInst = querySceneInstService.getKiteInst(custId, instType, rootInstId);
        if (Objects.isNull(kiteInst)) {
            return cateIds;
        }
        String cateId = Optional.ofNullable(OfferCache.get(kiteInst.getSpecId())).map(Offer::getCateId).orElse("");
        if (KiteStringUtils.isNotEmpty(cateId)) {
            cateIds.add(cateId);
        }
        if (InstType.GIFT_OFFER_INST.equals(instType)){
            List<KiteOfferInst> kiteOfferInsts = querySceneInstService
                .listMainOfferInstsFromGiftOfferInst(custId, kiteInst.getInstId());
            kiteOfferInsts.forEach(kiteOfferInst -> {
                String mainOfferCateId = Optional.ofNullable(OfferCache.get(kiteOfferInst.getSpecId())).map(Offer::getCateId).orElse("");
                if (KiteStringUtils.isNotEmpty(mainOfferCateId)) {
                    cateIds.add(mainOfferCateId);
                }
            });
        }
        return cateIds;
    }

    /**
     * 判断是否走用户中心落户，除物联网定制类、连接类和5grcs走老集客类落户，其他的新接产品都走用户中心落户。
     * @param cateId
     * @return
     */
    public static boolean isRouteUser(String sceneInstId,String cust_id) {
    	boolean result = true;
    	String flag = DcSystemParamCache.getDcParamVal("IS_ROUTE_USER");
    	if(!KiteStringUtils.equals(flag, "T")) {
    		return false;
    	}
        String cateId = getCateId(sceneInstId,cust_id);
        DcPublic dp = DcPublicCache.get("20210207001", cateId) ;
        if(Objects.nonNull(dp)) {
            result = false;
        }
        return result;
    }

    /**
     * 判断是不是二次类业务
     * @param cateId
     * @return
     */
    public static boolean isProdModify(String sceneInstId) {
    	boolean result = true;
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
    	String serviceOfferId = Optional
                .ofNullable(querySceneInstService.getSceneInst(sceneInstId))
                .map(KiteSceneInst::getServiceOfferId).orElse("");
        if (KiteStringUtils.equalsAny(serviceOfferId, "1", "1012", "1001", "1013", "1068")) {
        	result = false;
        }
        // bizType可能是逗号分隔的多个二次类业务,新购时等于1001,判断二次类业务时考虑用contains
        String bizType = querySceneInstService.getExtParameterValue(sceneInstId, "bizType");
        if (KiteStringUtils.equalsAny(bizType, "1001", "1012")) {
            result = false;
        }
        return result;
    }

    /**
     * 替换goods节点的InstanceId为订单中心返回的值
     * @param sceneInstId
     * @param cuccKitePosDto
     * @return
     */
    public static void replaceGoodsInstanceId(String sceneInstId, KitePosDTO cuccKitePosDto) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KitePosDTO infPosDto = ExtOrderInfoCache.get(sceneInstId);
        List<KitePosGoodsDTO> cuccGoods = null;
        if(null != cuccKitePosDto){
            cuccGoods = cuccKitePosDto.getGoods();
        }
        List<KitePosGoodsDTO> infPGoods = null ;
        if(null != infPosDto){
            infPGoods = infPosDto.getGoods();
        }
        if (KiteObjectUtils.anyNull(cuccKitePosDto, infPosDto, cuccGoods, infPGoods)) {
            return;
        }
        List<KitePosGoodsDTO> infGoodsDtos = infPosDto.getGoods();
        /*//配送信息
        if(!KiteObjectUtils.anyNull(infPosDto.getDelivery(),cuccKitePosDto.getDelivery())){
            cuccKitePosDto.getDelivery().forEach(delivery->{
                delivery.setInstanceId(infPosDto.getDelivery().get(0).getInstanceId());
            });
        }
        //合同
        if(!KiteObjectUtils.anyNull(infPosDto.getContract(),cuccKitePosDto.getContract())){
            cuccKitePosDto.getContract().forEach(contract->{
                contract.setInstanceId(infPosDto.getContract().get(0).getInstanceId());
            });
        }
        //折扣信息
        if(!KiteObjectUtils.anyNull(infPosDto.getDiscount(),cuccKitePosDto.getDiscount())){
            cuccKitePosDto.getDiscount().forEach(discount->{
                discount.setInstanceId(infPosDto.getDiscount().get(0).getInstanceId());
            });
        }
        //用户信息
        if(!KiteObjectUtils.anyNull(infPosDto.getUsers(),cuccKitePosDto.getUsers())){
            cuccKitePosDto.getUsers().forEach(user->{
                KitePosUserDTO infUserDto = infPosDto.getUsers().stream().filter(infUsers -> infUsers.getUserId().equals(user.getUserId()))
                    .findAny().orElse(null);
                if(Objects.nonNull(infUserDto)){
                    user.setInstanceId(infUserDto.getInstanceId());
                }
            });
        }
        //账户节点
        if(!KiteObjectUtils.anyNull(infPosDto.getAccounts(),cuccKitePosDto.getAccounts())){
            cuccKitePosDto.getAccounts().forEach(accounts->{
                KitePosAccountDTO infAccountDto = infPosDto.getAccounts().stream().filter(infAccounts -> infAccounts.getAccountId().equals(accounts.getAccountId()))
                    .findAny().orElse(null);
                if(Objects.nonNull(infAccountDto)){
                    accounts.setInstanceId(infAccountDto.getInstanceId());
                }
            });
        }*/
        //商品节点
        cuccKitePosDto.getGoods().forEach(goods -> {
            //goods节点InstanceId替换
            KitePosGoodsDTO infGoodsDto = infGoodsDtos.stream().filter(infGoods -> infGoods.getCode().equals(goods.getCode()))
                .findAny().orElse(null);
            if (Objects.nonNull(infGoodsDto)) {
                goods.setInstanceId(infGoodsDto.getInstanceId());
                goods.setParentInstId(infGoodsDto.getParentInstId());
                //处理资费的InstanceId,通过destItemId匹配
                if (KiteListUtils.isNotEmpty(goods.getFees()) && KiteListUtils.isNotEmpty(infGoodsDto.getFees())) {
                    List<KitePosGoodsFeeDTO> infFees = infGoodsDto.getFees();
                    goods.getFees().forEach(fee -> {
                        if (KiteStringUtils.isNotEmpty(fee.getDestItemId())) {
                            infFees.stream().filter(infFee -> KiteStringUtils.isEqual(fee.getDestItemId(), infFee.getDestItemId()))
                                .findAny().ifPresent(sourceFee -> fee.setInstanceId(sourceFee.getInstanceId()));
                        }
                        else {
                            //订购未落户的场景,取实例Id映射判断
                            Map<String, String> feeInstIdMap = querySceneInstService
                                .getExtParameterValue(sceneInstId, "feeInstIdMap_".concat(goods.getInstanceId()));
                            if (KiteMapUtils.isNotEmpty(feeInstIdMap)) {
                                fee.setInstanceId(feeInstIdMap.get(fee.getInstanceId()));
                            }
                        }
                    });
                }
                //替换product节点的InstanceId
                List<KitePosProductDTO> infProducts = infGoodsDto.getProducts();
                goods.getProducts().forEach(product -> {
                    KitePosProductDTO infProductDTO = infProducts.stream().filter(infProduct -> infProduct.getCode().equals(product.getCode()))
                        .findAny().orElse(null);
                    if (Objects.nonNull(infProductDTO)) {
                        product.setInstanceId(infProductDTO.getInstanceId());
                    }
                });
            }
        });
    }

    /**
     * 判断商品变更相关场景,做成配置的原因是目前只针对设备类开发,后续产品的商品变更服务提供可能不同,需求无法确认,如后续确认统一了可去除配置
     * @param sceneInstId
     * @return
     */
    public static boolean isGoodsModifyScene(String sceneInstId) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        String cfg = DcSystemParamCache.getDcParamVal("GoodsModifyScene");
        if (KiteStringUtils.isIndexOf(cfg, sceneInst.getServiceOfferId(), ",")){
            return true;
        }

        // 如果是追单的场景,取出原单的服务提供判断一下,取不到的必然不是商品变更,默认个1001,这个判断请保持在最后
        if (LocalServiceOfferConsts.SERVICE_OFFER_FOLLOW.equals(sceneInst.getServiceOfferId())) {
            String bizType = querySceneInstService.getExtParameterValue(sceneInst.getSceneInstId(), "serviceOfferId", "1001");
            return KiteStringUtils.isIndexOf(cfg, bizType, ",");
        }
        return false;
    }

    public static void setExtParamValue(KiteInst inst, String sceneInstId, String key, String value) {
        KiteAttr kiteAttr = new KiteAttr();
        kiteAttr.setFieldName(key);
        kiteAttr.setValue(value);
        kiteAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
        inst.setAttr(kiteAttr);
    }

    /**
     * 判断是否需要群组关系节点
     * 1、融合需要
     * 2、收入归集集团成员加入和退出需要
     * @param sceneInstId
     * @param custId
     * @return
     */
    public static boolean needPackageRelations(String sceneInstId, String custId) {
        //从dc中获取配置，判断当前是否是归集集团创建操作
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst kiteSceneInst = querySceneInstService.getSceneInst(sceneInstId);
        InstType rootInstType = kiteSceneInst.getRootInstType();
        if (KiteDcPublicUtils.isCollectionGroup(sceneInstId) || Objects.equals(InstType.GIFT_OFFER_INST, rootInstType)) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    /**
     * 查询客户列表接口
     * @param custId
     * @return
     */
    public static CuccCustInfoDTO queryNewCustInfo(String custId) {
        KiteCustomerInfoReq kiteCustomerInfoReq = new KiteCustomerInfoReq();
        CuccCustInfoDTO cuccCustInfoDTO = new CuccCustInfoDTO();
        kiteCustomerInfoReq.setCustId(custId);
        String staffCode = ContextUtil.getSimpleLoginInfo().getStaffCode();
        String eparchyCode = ContextUtil.getSimpleLoginInfo().getLanId();
        String provinceCode = ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr();
        kiteCustomerInfoReq.setStaffCode(staffCode);
        kiteCustomerInfoReq.setEparchyCode(eparchyCode);
        kiteCustomerInfoReq.setProvinceCode(provinceCode);
        kiteCustomerInfoReq.setPageNum(1);
        kiteCustomerInfoReq.setPageSize(10);
        // 调用查询客户列表
        ICustReceptionService custReceptionService = SpringUtil.getBean(ICustReceptionService.class);
        PageInfo<CuccCustInfoDTO> list = custReceptionService.customerListQueryNew(kiteCustomerInfoReq);
        if (!KiteObjectUtils.isEmpty(list) && KiteListUtils.isNotEmpty(list.getList())) {
            List<CuccCustInfoDTO> cuccCustInfoDTOList = list.getList();
            cuccCustInfoDTO = cuccCustInfoDTOList.get(0);
        }
        return cuccCustInfoDTO;
    }

    public static boolean isBatchAccept(String sceneInstId) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        return KiteStringUtils
            .equals(KeyConsts.IFTRUE_T, querySceneInstService.getExtParameterValue(sceneInstId, "isBatchAccept"));
    }

    /**
     * 判断是否含有趸交资费
     * @param sceneInstId
     * @return
     */
    public static List<KiteInst> queryOneOffFees(String sceneInstId) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        List<KiteInst> additionalOffers = querySceneInstService.listInsts(sceneInstId, Collections.singletonList(InstType.ADDITIONAL_OFFER_INST))
            .stream().filter(additionalOffer -> !KiteStringUtils.equalsAny(additionalOffer.getActionType().name(), ActionType.D.name(), ActionType.X.name()))
            .filter(additionalOffer -> isOneOffAddtionalOffer(additionalOffer.getSpecId()))
            .collect(Collectors.toList());
        return additionalOffers;
    }

    public static boolean isOneOffAddtionalOffer(String offerId) {
        Offer offer = ProdFeeCache.get(offerId);
        if (Objects.isNull(offer)) {
            return false;
        }
        return LocalKeyConsts.FEE_PAY_TYPE_ONE_OFF.equals(KiteMapUtils.getString(offer.getOfferMap(), "payType"));
    }

    /**
     * 1、如果是核查转定单,销售承接的第一个流程（上海是审核或签订，其他省是签订）也需要可以新增和编辑趸交资费
     * 2、如果不是,那么除了订单录入环节,其他环节均不允许新增、修改和删除趸交资费
     * @param sceneInstId
     * @return
     */
    public static boolean showAndEditOneOffAddionalOffer(String sceneInstId) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        //核查转定场景标识
        String isTransferOrderScene = querySceneInstService.getExtParameterValue(sceneInstId, "isTransferOrderScene");
        String nodeCode = querySceneInstService.getExtParameterValue(sceneInstId, "nodeCode");
        // 起租环节可以修改趸交资费的开始时间
        if (KiteStringUtils.isEqual("OrderStartRent", nodeCode)) {
            return true;
        }
        if (LocalKeyConsts.IFTRUE_T.equals(isTransferOrderScene)) {
            if (LocalKeyConsts.PROVINCE_SHANGHAI.equals(sceneInst.getProvinceNbr())) {
                //上海需要判断是否跨域
                List<KiteProdInst> prodInsts = querySceneInstService.listProdInstsFromOfferInst(sceneInst.getCustId(), sceneInst.getRootInstId());
                String province = querySceneInstService.getProdInstAttrValue(sceneInst.getCustId(), prodInsts.get(0).getProdInstId(), "2_0000220");
                if (KiteStringUtils.isEmpty(province)) {
                    return false;
                }
                return sceneInst.getProvinceNbr().equals(province) ? "OrderAudit".equals(nodeCode) : "OrderSigned".equals(nodeCode);
            }
            else {
                return "OrderSigned".equals(nodeCode);
            }
        }
        else {
            return KiteStringUtils.isEmpty(nodeCode);
        }
    }
}
